import java.util.Objects;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-04-14
 * Time:23:58
 */
class Lover {
    String name;//包访问权限--在对应包内，应该用隐藏的this来修饰滴
    int old;
    int year;

    public Lover(String name, int old, int year) {
        this.name = name;
        this.old = old;
        this.year = year;
    }

    @Override
    public String toString() {
        return "Lover{" +
                "name=" + name +
                ", old=" + old +
                ", year='" + year + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {//向上转型---形象为父类；实参为子类
        // return super.equals(o);
        //判断两个引用是否引用同一个对象
        if (this == o) {
            return true;
        }
        if (o != null || getClass() != o.getClass()) {//getClass方法是获得该对象的类的类型--判断类类型是否相同
            return false;
        }
        Lover lover = (Lover) o;//强行转化--子类--向下转型
        if (this.name.equals(lover.name) && old == ((Lover) o).old && year == lover.year) {
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
       return Objects.hash(name, old, year);//这个类的这个方法拿去计算啦
   }

}
public class Equals {
    public static void main(String[] args) {//内部类中不能有静态方法
        Lover lover1=new Lover("陈恋",20,1);
        Lover lover2=new Lover("唐健",19,1);
        System.out.println(lover1.equals(lover2));
        System.out.println("=====   对象的位置----->hashcode方法   =====");
        System.out.println(lover1.hashCode());
        System.out.println(lover2.hashCode());






    }
}

